package com.norteksoft.projectname.module1.service.impl;

import java.io.Serializable;

import com.norteksoft.projectname.module1.dao.AttachmentDao;
import com.norteksoft.projectname.module1.dao.DepartmentDao;
import com.norteksoft.projectname.module1.dao.PersonDao;
import com.norteksoft.projectname.module1.model.Attachment;
import com.norteksoft.projectname.module1.model.Department;
import com.norteksoft.projectname.module1.model.Person;
import com.norteksoft.projectname.module1.service.PersonManager;
import com.norteksoft.struts.dao.EntityDao;
import com.norteksoft.struts.service.HibernateEntityManager;
/**
 * @spring.bean id="personManager"
 * @author huhc
 *
 */
public class PersonManagerImpl extends HibernateEntityManager implements
		PersonManager {
	private PersonDao personDao;
	private DepartmentDao departmentDao;
	private AttachmentDao attachmentDao;
	
	//private DepartmentManager departmentManager;
	/**
	 * @spring.property ref="personDao"
	 * @param personDao
	 */
	public void setPersonDao(PersonDao personDao) {
		this.personDao = personDao;
		setEntityDao((EntityDao)personDao);
	}
	
//	/**
//	 * @spring.property ref="departmentManager"
//	 * @param departmentManager
//	 */
//	public void setDepartmentManager(DepartmentManager departmentManager) {
//		this.departmentManager = departmentManager;
//	}

	/**
	 * @spring.property ref="attachmentDao"
	 */
	public void setAttachmentDao(AttachmentDao attachmentDao) {
		this.attachmentDao = attachmentDao;
	}

	/**
	 * @spring.property ref="departmentDao"
	 * @param departmentDao
	 */
	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}
	public void save(Person person, String departmentId) {
		// TODO Auto-generated method stub
		//必须先加载父对象才能保存（在tomcat5下不用，weblogic8.1下要用 可能是jdk的不同版本造成的）
		person.setBelongDep((Department) departmentDao.get(Long.valueOf(departmentId)));
		personDao.save(person);
//		if(person.getId()!=null){
//			personDao.update(person,newFile,attachmeId);
//		}else{
//			personDao.save(person);
//		}
		
	}

	public Attachment getAttachment(Serializable id) {
		// TODO Auto-generated method stub
		return (Attachment) attachmentDao.get(id);
	}

	public Long getAttachmentId(Long personId) {
		// TODO Auto-generated method stub
		return personDao.getAttachmentId(personId);
	}

	public void deleteAttachment(Long id) {
		// TODO Auto-generated method stub
		personDao.deleteAttachment(id);
	}

	public Person getPerson(String name) {
		// TODO Auto-generated method stub
		return personDao.getPerson(name);
	}

	
	
}
